<?php
namespace App\DBs\Home;

use Illuminate\Support\Facades\DB;
use App\DBs\BaseDB as Base;

class TrendDB extends Base
{
    //大会动态

    public function __construct()
    {
    }

    //大会通知
    public function getTzIndex()
    {
        $res = DB::table($this->tMeet)->where('del',0)
            ->orderBy('id','desc')->skip(0)->take(4)->get();
        if (!count($res)) {
            return array('code'=>-2,'msg'=>'没有数据');
        }
        $res = $this->jsonToArr($res);
        $items = [];
        foreach ($res as $re) {
            $img = file_exists($re['img']) ? env('DOMAIN').'/'.$re['img'] : '';
            $items[] = [
                'id'=>$re['id'], 'title'=>$re['title'],
                'img'=>$img, 'chtime'=>$re['jointime'],
            ];
        }
        return array('code'=>0,'msg'=>'success','data'=>$items);
    }

    //聚焦大会
    public function getFocusIndex()
    {
        $res = DB::table($this->tFocus)->where('del',0)
            ->orderBy('id','desc')->skip(0)->take(4)->get();
        if (!count($res)) {
            return array('code'=>-2,'msg'=>'没有数据');
        }
        $res = $this->jsonToArr($res);
        $items = [];
        foreach ($res as $re) {
            $img = file_exists($re['img']) ? env('DOMAIN').'/'.$re['img'] : '';
            $detail = json_decode($re['detail'],true);
            $addtime = date('Y.m.d',strtotime($re['addtime']));
            $items[] = [
                'id'=>$re['id'], 'meetid'=>$re['meetid'], 'title'=>$re['title'],
                'detail'=>$detail, 'img'=>$img, 'addtime'=>$addtime,
            ];
        }
        return array('code'=>0,'msg'=>'success','data'=>$items);
    }

    //演讲嘉宾
    public function getSpeakerIndex()
    {
        $res = DB::table($this->tSpeaker)->where('del',0)
            ->orderBy('id','desc')->skip(0)->take(4)->get();
        if (!count($res)) {
            return array('code'=>-2,'msg'=>'没有数据');
        }
        $res = $this->jsonToArr($res);
        $items = [];
        foreach ($res as $re) {
            $uhead = file_exists($re['uhead']) ? env('DOMAIN').'/'.$re['uhead'] : '';
            $addtime = date('Y.m.d',strtotime($re['addtime']));
            $items[] = [
                'id'=>$re['id'], 'meetid'=>$re['meetid'], 'uname'=>$re['uname'],
                'udetail'=>$re['udetail'], 'uhead'=>$uhead, 'addtime'=>$addtime,
            ];
        }
        return array('code'=>0,'msg'=>'success','data'=>$items);
    }

    //资料下载
    public function getZiliao()
    {
        $res = DB::table($this->tFile)->where('del',0)
            ->orderBy('id','desc')->skip(0)->take(4)->get();
        if (!count($res)) {
            return array('code'=>-2,'msg'=>'没有数据');
        }
        $res = $this->jsonToArr($res);
        $items = [];
        foreach ($res as $re) {
            $link = file_exists($re['link']) ? env('DOMAIN').'/'.$re['link'] : '';
            $addtime = date('Y.m.d',strtotime($re['addtime']));
            $items[] = [
                'id'=>$re['id'], 'meetid'=>$re['meetid'], 'fname'=>$re['fname'],
                'link'=>$link, 'addtime'=>$addtime,
            ];
        }
        return array('code'=>0,'msg'=>'success','data'=>$items);
    }

    //资料下载
    public function getLearnIndex()
    {
        $res = DB::table($this->tLearn)->where('del',0)
            ->orderBy('id','desc')->skip(0)->take(4)->get();
        if (!count($res)) {
            return array('code'=>-2,'msg'=>'没有数据');
        }
        $res = $this->jsonToArr($res);
        $items = [];
        foreach ($res as $re) {
            $img = file_exists($re['img']) ? env('DOMAIN').'/'.$re['img'] : '';
            $detail = json_decode($re['detail'],true);
            $addtime = date('Y.m.d',strtotime($re['addtime']));
            $items[] = [
                'id'=>$re['id'], 'title'=>$re['title'], 'detail'=>$detail,
                'img'=>$img, 'addtime'=>$addtime,
            ];
        }
        return array('code'=>0,'msg'=>'success','data'=>$items);
    }

    //影像馆
    public function getYxgIndex()
    {
        $res = DB::table($this->tImgs)->where('del',0)->where('type',3)
            ->orderBy('id','desc')->skip(0)->take(4)->get();
        if (!count($res)) {
            return array('code'=>-2,'msg'=>'没有数据');
        }
        $res = $this->jsonToArr($res);
        $items = [];
        foreach ($res as $re) {
            $img = file_exists($re['img']) ? env('DOMAIN').'/'.$re['img'] : '';
            $items[] = [
                'id'=>$re['id'], 'img'=>$img,
            ];
        }
        return array('code'=>0,'msg'=>'success','data'=>$items);
    }
}